﻿using Engine;
using Game;
using TemplatesDatabase;

namespace Mekiasm.Common
{
    public class SaveItem : ComponentEnergyMachine
    {
        public int id = 0;

        public int Data = 0;

        public int Index = 0;

        public int x;

        public int y;

        public int z;

        public long fuelAmount;

        public int fuelValue;

        public SaveItem()
        {
        }

        public void CopyComponent(ComponentEnergyMachine machine)
        {
            ValuesDictionary pairs = new ValuesDictionary();
            machine.Save(pairs, null);
            base.Load(pairs, null);
        }

        public void Load(ValuesDictionary values)
        {
            base.Load(values, null);
        }

        public void Save(ValuesDictionary values)
        {
            base.Save(values, null);
        }

        public override bool Equals(object obj)
        {
            SaveItem toolSaveItem = obj as SaveItem;
            return toolSaveItem.id == id && toolSaveItem.Index == Index;
        }
        public override int GetHashCode()
        {
            return $"{id}:{Index}".GetHashCode();
        }

        public void DropItems(Vector3 position, int slotIndex, int count)
        {
            SubsystemPickables subsystemPickables = Project.FindSubsystem<SubsystemPickables>(true);
            int slotCount = GetSlotCount(slotIndex);
            if (slotCount - count >= 0)
            {
                int slotValue = GetSlotValue(slotIndex);
                RemoveSlotItems(slotIndex, count);
                Vector3 value = m_random.Float(5f, 10f) * Vector3.Normalize(new Vector3(this.m_random.Float(-1f, 1f), this.m_random.Float(1f, 2f), this.m_random.Float(-1f, 1f)));
                subsystemPickables.AddPickable(slotValue, count, position, new Vector3?(value), null);
            }
        }

    }

}
